<script setup>
import {reqUserOrder} from '@/api/order'
import {ref, onMounted} from 'vue'
// tab列表
const tabTypes = [
  {name: "all", label: "全部订单"},
  {name: "unpaid", label: "待付款"},
  {name: "deliver", label: "待发货"},
  {name: "receive", label: "待收货"},
  {name: "comment", label: "待评价"},
  {name: "complete", label: "已完成"},
  {name: "cancel", label: "已取消"}
]
// 订单列表
const orderList = ref([])
// 当前tab
const currentTab = ref('all')
const params = ref({
  orderState: 0,
  page: 1,
  pageSize: 2
})
const total = ref(0)

onMounted(() => getOrderList())
// 获取订单列表
const getOrderList = async() => {
  const res = await reqUserOrder(params.value)
  orderList.value = res.data.result
  total.value = res.data.total
  console.log(res.data.result)
}

// tab切换
const tabChange = (type) => {
  console.log(type)
  params.value.orderState = type
  getOrderList()
}

// 页码切换
const pageChange = (page) => {
  console.log(page)
  params.value.page = page
  getOrderList()
}



</script>

<template>
  <div class="order-list">
    <el-tabs @tab-change="tabChange" style="padding: 10px 20px;">
      <!-- tab切换 -->
      <el-tab-pane v-for="item in tabTypes" :key="item.name" :label="item.label"/>
    </el-tabs>
    <div class="main-container">
      <div class="no-list" v-if="orderList.length === 0">
        <el-empty description="暂无订单数据" />
      </div>

      <!-- 订单列表 -->
      <!-- 分页 -->
      <el-pagination
          :total="total"
          @current-change="pageChange"
          :page-size="params.pageSize" background
          layout="prev, pager, next, jumper,total"
      />

    </div>
  </div>
</template>

<style scoped lang="scss">
.order-list {
  width: 100%;
  height: 100%;

  .main-container {
    min-height: 500px;
    padding: 0 20px;

    .no-list {
      min-height: 500px;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}

.order-item {
  margin-bottom: 20px;
  border: 1px solid #f5f5f5;

  .head {
    height: 50px;
    line-height: 50px;
    background: #f5f5f5;
    padding: 0 20px;
    overflow: hidden;

    span {
      margin-right: 20px;

      &.down-time {
        margin-right: 0;
        float: right;

        i {
          vertical-align: middle;
          margin-right: 3px;
        }

        b {
          vertical-align: middle;
          font-weight: normal;
        }
      }
    }

    .del {
      margin-right: 0;
      float: right;
      color: #999;
    }
  }

  .body {
    display: flex;
    align-items: stretch;

    .column {
      border-left: 1px solid #f5f5f5;
      text-align: center;
      padding: 20px;

      > p {
        padding-top: 10px;
      }

      &:first-child {
        border-left: none;
      }

      &.goods {
        flex: 1;
        padding: 0;
        align-self: center;

        ul {
          li {
            border-bottom: 1px solid #f5f5f5;
            padding: 10px;
            display: flex;

            &:last-child {
              border-bottom: none;
            }

            .image {
              width: 70px;
              height: 70px;
              border: 1px solid #f5f5f5;
            }

            .info {
              width: 220px;
              text-align: left;
              padding: 0 10px;

              p {
                margin-bottom: 5px;

                &.name {
                  height: 38px;
                }

                &.attr {
                  color: #999;
                  font-size: 12px;

                  span {
                    margin-right: 5px;
                  }
                }
              }
            }

            .price {
              width: 100px;
            }

            .count {
              width: 80px;
            }
          }
        }
      }

      &.state {
        width: 120px;

        .green {
          color: #57c59f;
        }
      }

      &.amount {
        width: 200px;

        .red {
          color: #ff4949;
        }
      }

      &.action {
        width: 140px;

        a {
          display: block;

          &:hover {
            color: #57c59f;
          }
        }
      }
    }
  }
}

</style>